package query

import (
	"errors"
	"ssadmin/common/query"
	"time"
)

type UserQuery struct {
	query.Pagination `search:"-"`
	UserId           string    `form:"id"  search:"type:exact;column:id;table:sys_user"`
	Username         string    `form:"c"  search:"type:contains;column:username;table:sys_user"`
	UsernameEq       string    `form:"username"  search:"type:exact;column:username;table:sys_user"`
	Status           string    `form:"status"  search:"type:exact;column:status;table:sys_user"`
	Email            string    `form:"email"  search:"type:contains;column:email;table:sys_user"`
	Mobile           string    `form:"mobile"  search:"type:contains;column:mobile;table:sys_user"`
	CreateTime       time.Time `form:"createTime"  search:"type:order;column:create_time;table:sys_user"`
	Search           string    `form:"search"  search:"type:contains;column:username;table:sys_user"`
	Openid           string    `form:"openid"  search:"type:exact;column:open_id;table:sys_user"`
	Self             bool      `form:"self"  search:"-"`
	UserIds          []string  `form:"-"  search:"type:in;column:user_id;table:sys_user"`
	CreatorId        string    `form:"-"  search:"-"` //通过用户机构权限查询
	DeptIds          []string  `form:"-"  search:"-"`
	RoleId           string    `form:"roleId"  search:"-"`
	UserOrder

	QueryUserId string `form:"queryUserId"  search:"-"`
	CreatorIdEq string `search:"type:exact;column:creator_id;table:sys_user"`
}

type UserOrder struct {
	Username      string    `form:"usernameOrder"  search:"type:order;column:username;table:sys_user"`
	Email         string    `form:"emailOrder"  search:"type:order;column:email;table:sys_user"`
	Mobile        string    `form:"mobileOrder"  search:"type:order;column:mobile;table:sys_user"`
	Status        string    `form:"statusOrder"  search:"type:order;column:status;table:sys_user"`
	CreateTime    string    `form:"createTime"  search:"type:order;column:create_time;table:sys_user"`
	ModifyTime    time.Time `form:"modifyTimeOrder"  search:"type:order;column:modify_time;table:sys_user"`
	LastLoginTime time.Time `form:"lastLoginTimeOrder"  search:"type:order;column:last_login_time;table:sys_user"`
}

func (m *UserQuery) GetNeedSearch() interface{} {
	return *m
}

func (m *UserQuery) GetId() interface{} {
	if len(m.UserId) == 0 {
		return errors.New("ID不能为空")
	}
	return *m
}

// UserGetReq 功能获取请求参数
type UserGetReq struct {
	UserId   string `form:"id" search:"type:exact;column:id;table:sys_user"`
	Username string `form:"username" search:"type:exact;column:username;table:sys_user"`
}

func (s *UserGetReq) GetId() interface{} {
	return s.UserId
}
